<?php
    $entity = pc_variable("entity");
    $attribute = pc_variable("attribute");
    $name = pc_variable("name");
    $value = pc_variable("value");
    $errors = pc_variable("errors");
    if($errors !== null && $errors->get($name) !== null) {
        $value = pc_variable("entity." . $name);
    } else if($value !== null) {
        $value = $value->getId();
    }
?>
<label for="entity.<?php pc_echo($name); ?>"<?php if($attribute->isRequired()) { ?> class="required"<?php } ?>><?php pc_echo(pc_message("field." . $name)); ?></label>
<select id="entity.<?php pc_echo($name); ?>" name="entity.<?php pc_echo($name); ?>">
    <option value=""></option>
    <?php
        if($entity !== null && $entity->getType() == $attribute->getType()) {
            pc_pagelet(
                "show-entity/attribute/reference-list",
                array(
                    "typeName" => $attribute->getType()->getFullName(),
                    "propertyNames" => array("id"),
                    "operators" => array("!="),
                    "values" => array($entity->getId()),
                    "id" => $value),
                "Query");
        } else {
            pc_pagelet(
                "show-entity/attribute/reference-list",
                array(
                    "typeName" => $attribute->getType()->getFullName(),
                    "id" => $value),
                "Query");
        }
    ?>
</select>
<br/>
